package org.example.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

@RequestMapping("ct4")
@Controller
public class test_1_4 {
    @RequestMapping("/test1")
    public Object test1() {
        return "/index.html";
    }
    @RequestMapping("/test2")
    public String test2() {
        return "返回的是数据";
    }
    @ResponseBody
    @RequestMapping("/test3")
    public String test3() {
        return "<h1>遇事问春风乄<h1>";
    }
    @RequestMapping("/test4")
    @ResponseBody
    public HashMap<String, String> test4() {
        HashMap<String, String> map = new HashMap<>();
        map.put("Java", "Java Value");
        map.put("MySQL", "MySQL Value");
        map.put("Redis", "Redis Value");
        return map;
    }
    @RequestMapping("/test5")
    @ResponseBody
    public String test5(HttpServletResponse response) {
        response.setStatus(520);
        return "修改参数成功";
    }
    @RequestMapping(value = "/test6",produces = "application/json")
    @ResponseBody
    public String test6() {
        return "数据格式为：application/json";
    }
    @RequestMapping("test7")
    @ResponseBody
    public String test7(HttpServletResponse response) {
        response.setHeader("MyHeader","MyHeaderValue");
        return "设置Header成功";
    }
}
